package com.chixing.service.impl;

import com.chixing.mapper.HousewonMapper;
import com.chixing.pojo.Housewon;
import com.chixing.pojo.HousewonExample;
import com.chixing.service.HousewonService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dwe
 * @date 2021-10-13 21:27
 */
@Service
public class HousewonServiceImpl implements HousewonService {
    @Autowired
    private HousewonMapper housewonMapper;

    @Override
    public ServerResponse saveHouse(Housewon housewon) {
        int rows = housewonMapper.insert(housewon);
        if (rows > 0 ){
            return ServerResponse.saveSuccess(rows);
        }
        return ServerResponse.saveFail(rows);
    }

    @Override
    public ServerResponse getByHouseIdAndHousewonName(Integer houseId, String housewonName) {
        Housewon housewon = null;
        HousewonExample example = new HousewonExample();
        example.createCriteria().andHousewonIdcardEqualTo(housewonName).andHousewonIdEqualTo(houseId);
        List<Housewon> housewonList = housewonMapper.selectByExample(example);
        if (housewonList.size() > 0){
            housewon = housewonList.get(0); //该地址该房东该房源只有一个
            return ServerResponse.getSuccess(housewon);
        }
        return ServerResponse.getFail(null);
    }
}
